const sqlite3 = require('../node_modules/sqlite3').verbose();
const path = require('path');
const dbPath = path.join(__dirname, '..', 'data', 'pph.sqlite');
const db = new sqlite3.Database(dbPath);

console.log('Running migration: add column motor_takt_time to pph_targets if missing');

db.all("PRAGMA table_info(pph_targets)", (err, rows) => {
  if (err) {
    console.error('Failed to read table info:', err.message);
    process.exit(1);
  }
  const has = Array.isArray(rows) && rows.some(r => r.name === 'motor_takt_time');
  if (has) {
    console.log('Column motor_takt_time already exists. Nothing to do.');
    return db.close();
  }
  db.run("ALTER TABLE pph_targets ADD COLUMN motor_takt_time REAL", (e2) => {
    if (e2) {
      console.error('Add column failed:', e2.message);
    } else {
      console.log('Column motor_takt_time added successfully.');
    }
    db.close();
  });
});

